package org.example.controller;

import org.example.model.Book;
import org.example.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;
import java.util.Map;

@Controller  //表示当前类是一个控制器类
@RequestMapping("/book")
public class BookController {
    @Autowired
    private BookService bookService;

    @GetMapping(value = "/getBookList",produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public List<Book> getBookList(int btype,String name){
        System.out.println(btype);
        System.out.println(name);
        List<Book> bookList = bookService.getBooksByTypeAndName(btype, name);
        return bookList;
    }

    @RequestMapping(value = "/getName")
    public String getName(Model model) {
        model.addAttribute("msg", "欢迎你");
        return "first";
    }


    @PostMapping(value = "/getBookName")
    @ResponseBody
    public Book getBookName(@RequestBody Book book) {
        System.out.println(book.getBtype());
        Book book1 = new Book();
        book1.setBname("活着");
        // model.addAttribute("bookName", "Your Book Title");
        return book1; // Specify a different view name
    }


}
